package edu.fiu.cis.personalize.server.clean;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

import edu.fiu.cis.personalize.shared.DefaultBlock;
import edu.fiu.cis.personalize.shared.ManagedBlock;

public class StopKeywords {
	private static Set<String> stopWords = new HashSet<String>();

	static {
		init();
	}

	public static void init() {
		ManagedBlock.exceptionHandled(new DefaultBlock() {

			@Override
			public Void execute() throws Exception {
				BufferedReader reader = new BufferedReader(
						new InputStreamReader(StopKeywords.class
								.getResourceAsStream("stopwords.txt")));
				while (reader.ready()) {
					String s = reader.readLine();
					StringTokenizer st = new StringTokenizer(s, " ,");
					while (st.hasMoreTokens()) {
						stopWords.add(st.nextToken());
					}
				}
				return null;
			}
		});

	}

	public static boolean isStopWord(String e) {
		return stopWords.contains(e.toLowerCase());
	}

	public static void main(String[] args) {
		System.out.println(isStopWord("at"));
	}

}
